<template>
  <div class="Carousel">
    <div class="banxin Carousel_box tanxin">
      <div class="box_l">&lt;</div>
      <ul class="tanxin Carousel_ul">
        <li
          :class="{ acitve: tuList[index] }"
          v-for="(item, index) in bannerImg"
          :key="index"
        >
          <img :src="item.imageUrl" alt="" />
        </li>
      </ul>
      <div class="box_r">&gt;</div>

      <div class="Carousel_img">
        <img src="../assets/images/download.png" alt="" />
      </div>
      <ul class="tanxin Carousel_sul">
        <li
          :class="{ active: tuList[index] }"
          v-for="(item, index) in tuList"
          :key="index"
        ></li>
      </ul>
    </div>
  </div>
</template>

<script>
import { BannerApi } from "@/request/api";
export default {
  data() {
    return {
      tuList: [],
      kzbianh: 0,
      bannerImg: [],
    };
  },
  created() {
    BannerApi().then((res) => {
      // console.log(res.data.banners);
      this.bannerImg = res.data.banners;
      this.tuList = this.bannerImg.map(() => false);
    });
    setInterval(() => {
      if (this.kzbianh > this.bannerImg.length - 1) {
        this.kzbianh = 0;
      }
      this.tuList = this.bannerImg.map(() => false);

      this.tuList.splice(this.kzbianh, 1, true);
      this.kzbianh++;
    }, 2000);
  },
};
</script>
 
<style lang = "less" scoped>
@import "../assets/base.less";
.Carousel {
  height: 300px;
  .Carousel_box {
    height: 250px;
    position: relative;
    .box_l,
    .box_r {
      width: 25px;
      height: 40px;
      background-color: rgba(0, 0, 0, 0.5);
      position: absolute;
      top: 120px;
      color: #fff;
      font-family: "宋体";
      text-align: center;
      line-height: 40px;
      font-size: 30px;
    }
    .box_l {
      left: -20px;
    }
    .box_r {
      right: -20px;
    }
    .Carousel_ul {
      position: absolute;
      left: 0px;
      li {
        transition: all 0.7s;
        position: absolute;
        top: 0;
        opacity: 0;
        &.acitve {
          opacity: 1;
        }
        img {
          height: 300px;
          width: 790px;
        }
      }
    }
    .Carousel_sul {
      width: 300px;
      position: absolute;
      left: 150px;
      bottom: -320px;
      transition: all 0.5;
      height: 300px;
      li {
        width: 10px;
        height: 10px;
        border-radius: 50%;
        background-color: rgba(255, 255, 255, 0.3);
        transition: all 0.5;
        &.active {
          background-color: @red;
        }
      }
    }
    .Carousel_img {
      width: 310px;
      height: 300px;
      overflow: hidden;
      position: absolute;
      top: 0;
      right: 0;
      img {
        position: absolute;
        top: -40px;
        width: 310px;
      }
    }
  }
}
</style>